package org.xyz.util;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;

public final class DeviceHelper {
	private String mImei;
	private String mSIM;
	private String mMobileVersion;
	private Context mContext;
	private String WifiMac = "";
	private String BlueMac = "";
	/**
	 * 手机型号
	 */
	private String Model = Build.MODEL;
	/**
	 * 品牌
	 */
	private String Brand = android.os.Build.BRAND;
	private String deviceId = "";

	public DeviceHelper(Context context) {
		mContext = context;
		findData();
	}

	TelephonyManager mTm = null;

	final private void findData() {
		mTm = (TelephonyManager) mContext
				.getSystemService(Context.TELEPHONY_SERVICE);
		mImei = mTm.getDeviceId();
		setMobileVersion(mTm.getDeviceSoftwareVersion());
		mSIM = mTm.getSimSerialNumber();
		String _id = mTm.getDeviceId();
		if (_id != null)
			deviceId = _id;
		WifiManager wifiMgr = (WifiManager) mContext
				.getSystemService(Context.WIFI_SERVICE);
		WifiInfo info = (null == wifiMgr ? null : wifiMgr.getConnectionInfo());
		if (null != info) {
			WifiMac = info.getMacAddress();
		}
		BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
		if (adapter != null) {
			String _BlueMac = adapter.getAddress();
			if (_BlueMac != null)
				setBlueMac(_BlueMac);
		}
		if (WifiMac == null) {
			WifiMac = "";
		}
		adapter = null;
		info = null;
		wifiMgr = null;
		System.gc();
	}

	final public String getDeviceId() {
		return deviceId;
	}

	final public String getImei() {
		return mImei;
	}

	final public String getSIM() {
		return mSIM;
	}

	/**
	 * 获得手机型号
	 * 
	 * @return
	 */
	final public String getModel() {
		return Model;
	}

	/**
	 * 判断是否模拟器。如果返回TRUE，则当前是模拟器
	 * 
	 * @return
	 */
	final public static boolean isEmulator() {
		return (Build.MODEL.equals("sdk"))
				|| (Build.MODEL.equals("google_sdk"));
	}

	public String getMobileVersion() {
		return mMobileVersion;
	}

	public void setMobileVersion(String mMobileVersion) {
		this.mMobileVersion = mMobileVersion;
	}

	public String getBlueMac() {
		return BlueMac;
	}

	public void setBlueMac(String blueMac) {
		BlueMac = blueMac;
	}

	public String getBrand() {
		return Brand;
	}

	public void setBrand(String brand) {
		Brand = brand;
	}

}
